#include "point.h"

Point::Point(){
	this->x1 = 0.0f;
	this->x2 = 0.0f;
	this->x3 = 0.0f;
	this->x4 = 1.0f;
}

Point::Point(float x1,float x2,float x3){
	this->x1 = x1;
	this->x2 = x2;
	this->x3 = x3;
	this->x4 = 1.0f;
}

Point::Point(float x1,float x2,float x3,float x4){
	this->x1 = x1;
	this->x2 = x2;
	this->x3 = x3;
	this->x4 = x4;
}

bool Point::operator ==(const Point& p2)const{
	return (this->x1==p2.x1&&this->x2==p2.x2&&this->x3==p2.x3);
}

Point Point::operator-(const Point& p2)const{
	return Point (this->x1-p2.x1,this->x2-p2.x2,this->x3-p2.x3);
}

Point Point::operator+(const Point& p2)const{
	return Point (this->x1+p2.x1,this->x2+p2.x2,this->x3+p2.x3);
}

Point& Point::operator+=(const Point& p2){
	this->x1+=p2.x1;
	this->x2+=p2.x2;
	this->x3+=p2.x3;
	return (*this);
}

Point& Point::operator-=(const Point& p2){
	this->x1-=p2.x1;
	this->x2-=p2.x2;
	this->x3-=p2.x3;
	return (*this);
}

Point& Point::operator*=(const float k){
	this->x1*=k;
	this->x2*=k;
	this->x3*=k;
	return *this;
}

Point Point::operator*(const float k)const{
	return Point(this->x1*k,this->x2*k,this->x3*k);
}

float Point::operator*(const Point p2)const{
	return (this->x1*p2.x1+this->x2*p2.x2+this->x3*p2.x3);
}

Point Point::cross(const Point& point)const{
	return Point(	this->x2*point.x3 - this->x3*point.x2,
					this->x3*point.x1 - this->x1*point.x3,
					this->x1*point.x2 - this->x2*point.x1);
}

float Point::mod()const{
	return sqrt(pow(this->x1,2)+pow(this->x2,2)+pow(this->x3,2));
}

float Point::operator [](int num)const{
	switch(num){
		case 1:
			return x1;
		case 2:
			return x2;
		case 3:
			return x3;
		case 4:
			return x4;
		default:
			throw PointException("Mal indice");
	}
}

float& Point::operator [](int num){
	switch(num){
		case 1:
			return x1;
		case 2:
			return x2;
		case 3:
			return x3;
		case 4:
			return x4;
		default:
			throw PointException("Mal indice");
	}
}
